home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / sviluppo / svilupp2 / amphn192.lha / src / StringRequest.c < prev    next >
C/C++ Source or Header  |  1996-11-16  |  5KB  |  168 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/intuitionbase.h>
  5. #include <intuition/screens.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <libraries/gadtools.h>
  8. #include <exec/types.h>
  9. #include <exec/libraries.h>
  10. #include <libraries/dos.h>            /* contains RETURN_OK, RETURN_WARN #def's */
  11. #include <clib/exec_protos.h>
  12. #include <clib/intuition_protos.h>
  13. #include <clib/gadtools_protos.h>
  14. #include <string.h>
  15. #include <errno.h>
  16. #include <libraries/gadtools.h>
  17.  
  18. extern struct Library *GadToolsBase;
  19.  
  20. #include "codec.h"
  21. #include "AmiPhone.h"
  22. #include "stringrequest.h"
  23.  
  24. /* Lets the user put a string into szBuffer.  Returns TRUE if the user entered
  25.    a string, otherwise FALSE */
  26. BOOL GetUserString (struct Screen *Scr, struct Window *PhoneWindow, char *szBuffer, char *szTitle, char *szGadText, int nLength)
  27. {
  28.     ULONG winsig, signals;
  29.     int fwindowwidth = Scr->Width/2, fwindowheight = 35 + Scr->RastPort.TxHeight;
  30.     int fwindowleft = (PhoneWindow->LeftEdge + (PhoneWindow->Width/2) - (fwindowwidth/2));
  31.     int fwindowtop  = (PhoneWindow->TopEdge  + (PhoneWindow->Height/2)- (fwindowheight/2));
  32.     struct NewGadget stringGad;
  33.     struct IntuiMessage *imsg;
  34.     struct Gadget *newgad = NULL;
  35.     struct Gadget *Stringgadlist = NULL;
  36.     void *Stringvi;
  37.     struct Window *Stringwindow;
  38.     BOOL done=FALSE, BRet = TRUE;
  39.     struct TextAttr topaz8 = {(STRPTR)"topaz.font", 8, 0x00, 0x00 };
  40.  
  41.     if (szTitle == NULL) szTitle = "String Requester Active";
  42.     if (szBuffer == NULL) return(FALSE);
  43.  
  44.     /* Allow strings starting with ASCII 1 to be treated as an empty string */
  45.     if (*szBuffer == '\1') *szBuffer = '\0';
  46.     if (*szTitle  == '\1') *szTitle  = '\0';
  47.     if (*szGadText== '\1') *szGadText= '\0';
  48.     
  49.     Stringvi = GetVisualInfo(Scr, TAG_END);
  50.  
  51.     if (Stringvi == NULL) 
  52.     {
  53.         return(FALSE);
  54.     }
  55.     
  56.     if (fwindowleft < 0) fwindowleft = PhoneWindow->LeftEdge;
  57.     if (fwindowheight < 0) fwindowtop = PhoneWindow->TopEdge;
  58.  
  59.     newgad = CreateContext(&Stringgadlist);
  60.     if (newgad == NULL) return(FALSE);
  61.  
  62.     stringGad.ng_TextAttr     = &topaz8;
  63.     stringGad.ng_VisualInfo  = Stringvi;
  64.     stringGad.ng_LeftEdge     = 5;
  65.     stringGad.ng_TopEdge        = 18 + Scr->RastPort.TxHeight;
  66.     stringGad.ng_Width     = (fwindowwidth-10);
  67.     stringGad.ng_Height     = 13;
  68.     stringGad.ng_GadgetText  = szGadText;
  69.     stringGad.ng_GadgetID     = 35;    
  70.     stringGad.ng_Flags     = PLACETEXT_ABOVE;
  71.  
  72.     newgad = CreateGadget(STRING_KIND, newgad, &stringGad, 
  73.                   GTST_String, szBuffer, 
  74.                   STRINGA_Justification, GACT_STRINGCENTER, 
  75.                   GA_Immediate, TRUE,
  76.                   TAG_END);  
  77.               
  78.      if (newgad == NULL) 
  79.     {
  80.         FreeGadgets(Stringgadlist);
  81.         FreeVisualInfo(Stringvi);
  82.         return(FALSE);
  83.     }
  84.     
  85.     if (GadToolsBase->lib_Version == 37)
  86.     {
  87.     /* Only do it the "illegal" way under v37.  GA_Immediate in the CreateGadget
  88.        line, above, won't work under v37 but will on later releases. */
  89.         newgad->Activation |= GACT_IMMEDIATE; 
  90.     }
  91.  
  92.     Stringwindow = OpenWindowTags(NULL,
  93.         WA_Left,        fwindowleft,
  94.         WA_Top,            fwindowtop,
  95.         WA_Width,           fwindowwidth,
  96.         WA_Height,        fwindowheight,
  97.         WA_PubScreen,        Scr,
  98.         WA_PubScreenFallBack,     TRUE,
  99.         WA_IDCMP,        STRINGIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_ACTIVEWINDOW,
  100.         WA_Flags,        WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  101.         WA_Gadgets,        Stringgadlist,
  102.         WA_Title,           szTitle,
  103.         WA_ScreenTitle,        "AmiPhone String Requester",
  104.         TAG_DONE );
  105.  
  106.     if (Stringwindow == NULL) 
  107.     {
  108.         FreeVisualInfo(Stringvi);
  109.         return(FALSE);
  110.     }
  111.     GT_RefreshWindow(Stringwindow, NULL); 
  112.  
  113.     SetBusyPointer(PhoneWindow);
  114.  
  115.     winsig = 1 << Stringwindow->UserPort->mp_SigBit;
  116.  
  117.     while (done==FALSE)
  118.     {
  119.         signals = Wait(winsig);
  120.         if (signals&winsig)
  121.         {
  122.             while ((done==FALSE) && (imsg = GT_GetIMsg(Stringwindow->UserPort)))
  123.             {
  124.                 switch(imsg->Class)
  125.                 {            
  126.                 case IDCMP_ACTIVEWINDOW:
  127.                     ActivateGadget(newgad,Stringwindow,NULL);
  128.                     break;
  129.                         
  130.                 case IDCMP_GADGETUP:
  131.                     Strncpy(szBuffer,((struct StringInfo*)newgad->SpecialInfo)->Buffer,nLength);
  132.                     done = TRUE;
  133.                     break;
  134.         
  135.                 case IDCMP_CLOSEWINDOW:
  136.                     done = TRUE;
  137.                     BRet = FALSE;
  138.                     break;
  139.                     
  140.                 case IDCMP_REFRESHWINDOW:
  141.                     GT_BeginRefresh(Stringwindow);
  142.                     GT_EndRefresh(Stringwindow, TRUE);
  143.                     break;
  144.                 }
  145.             GT_ReplyIMsg(imsg);
  146.             }
  147.         }
  148.     }
  149.     CloseWindow(Stringwindow);
  150.     FreeGadgets(Stringgadlist);
  151.     FreeVisualInfo(Stringvi); 
  152.     Stringwindow = NULL;
  153.     ClearPointer(PhoneWindow);
  154.     return(BRet);
  155. }
  156.  
  157. void SetBusyPointer(struct Window *win)
  158. {
  159.     static __chip UWORD waitPointer[] =
  160.            {0x0000, 0x0000, 0x0400, 0x07c0, 0x0000, 0x07c0, 0x0100, 0x0380,
  161.         0x0000, 0x07e0, 0x07c0, 0x1ff8, 0x1ff0, 0x3fec, 0x3ff8, 0x7fde,
  162.         0x3ff8, 0x7fbe, 0x7ffc, 0xff7f, 0x7efc, 0xffff, 0x7ffc, 0xffff,
  163.         0x3ff8, 0x7ffe, 0x3ff8, 0x7ffe, 0x1ff0, 0x3ffc, 0x07c0, 0x1ff8,
  164.         0x0000, 0x07e0, 0x0000, 0x0000};
  165.         
  166.     if (win != NULL) SetPointer(win, waitPointer, 16, 16, -6, 0);
  167. }
  168.